<template>
  <router-link
    class="ui-navmenu-item"
    :class="['ui-navmenu-item--' + type, {'is-collapse': collapse}]"
    :to="url"
  >
    <span
      class="ui-navmenu-item__icon"
      v-if="icon"
    >
      <ui-icon :name="icon" size="20px"></ui-icon>
    </span>
    <div class="ui-namenu-item__main"><slot /></div>
  </router-link>
</template>
<script>
export default {
  name: 'UiNavmenuItem',
  inject: ['UiNavmenu'],
  props: {
    url: {
      type: String,
      default: ''
    },
    icon: {
      type: String
    },
    iconSize: {
      type: String,
      default: '20px'
    }
  },
  computed: {
    type () {
      return this.UiNavmenu.type
    },
    collapse () {
      return this.UiNavmenu.collapse
    },
    iconStyle() {
      const sy = {}
      if (this.iconSize) {
        sy.width = this.iconSize
        sy.height = this.iconSize
        sy['background-size'] = this.iconSize
      }
      if (this.icon) {
        sy['background-image'] = `url(${this.icon})`
      }
      return sy
    }
  }
}
</script>
<style lang="less">
.ui-navmenu-item{
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 32px;
  line-height: 32px;
  text-decoration: none;
  &.is-collapse {
    .ui-namenu-item__main{
      opacity: 0;
    }
  }
}
.ui-navmenu-item__icon{
  display: inline-block;
  width: 20px;
  height: 20px;
  margin-right: 6px;
  line-height: 1em;
  background-repeat: no-repeat;
  background-position: 50% 50%;
}
.ui-namenu-item__main{
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all .25s;
  opacity: 1;
}
.ui-navmenu-item--default {
  border-radius: 5px;
  color: #666;
  padding: 1px 12px;
  margin: 6px 0;
  &:hover {
    color: #666;
    background-color: rgba(0,0,0,.03);
  }
  &.router-link-active {
    background-color: #DFEBFF;
    color: #3385FF;
    font-weight: bold;
  }
  &.is-collapse {
    padding-left: 22px;
  }
}
.ui-navmenu-item--primary {
  color: #fff;
  padding: 4px 12px;
  opacity: .7;
  &:hover {
    opacity: 1;
    color: #fff;
  }
  &.router-link-active {
    background-color: #4a90fa;
    color: #fff;
    font-weight: bold;
    opacity: 1;
  }
  &.is-collapse {
    padding-left: 20px;
  }
}
</style>
